#ifndef CUSTOMHANDLER_H
#define CUSTOMHANDLER_H

#include <QObject>
#include <QHash>
#include <QFile>
#include <vector>
#include "AbstractLayer/MsgHandler/myjson.h"
#include "UserLayer/External/enumlib.h"
class CustomHandler : public QObject
{
    Q_OBJECT
public:
    static CustomHandler* getInstance();
    static void setUseroc(const QString& useroc);
    void handle(const QByteArray& arr);
    int KMPSIndexOf(const QByteArray &text, const QByteArray &pattern,const int startIndex);
signals:
    void s_recvFriendInfo(const QString& name);
    void s_friendApplyAccess(const QString& friendoc,const QString& friendname);
    void s_haveFriendApply(const QString& friendoc,const QString& friendname,EnumLib::ApplyStatus status);
    void s_recvContact(const QString& oc,const QString& name);
    void s_recvUserInfo(const QString& name);
    void s_recvOneContact();
    void s_recvContactlistDone(const QList<QPair<QString,QString>>& list);
    void s_fileBlock(const QString& index,const QString& size,const QByteArray& data);
private slots:
    void recvFriendInfo(const QByteArrayList& arglist);
    void friendApplyAccess(const QByteArrayList& arglist);
    void haveFriendApply(const QByteArrayList& arglist);
    void analysisContactList(const QByteArrayList& arglist);
    void recvUserInfo(const QByteArrayList& arglist);
    void contactlistEnd(const QByteArrayList& arglist);
    void dealFileBlock(const QByteArrayList& arglist);
private:
    CustomHandler();
    std::vector<int> computeLPSArray(const QByteArray &pattern);
    std::vector<int> KMPSearch(const QByteArray &text, const QByteArray &pattern);
    QByteArrayList splitStringUsingKMP(const QByteArray &mainString, const QByteArray &delimiter);

    static CustomHandler* handler;
    static QHash<QString,QByteArray> hash;
    static QString useroc;
    QList<QPair<QString,QString>> contactlist;
};

#endif // CUSTOMHANDLER_H
